/*
 * Copyright (c) 2010 Curtis Boyden.  All rights reserved. 
 * This software was developed by Curtis Boyden and is provided under the terms 
 * of the GNU Lesser General Public License, Version 2.1. You may not use 
 * this file except in compliance with the license. If you need a copy of the license, 
 * please go to http://www.gnu.org/licenses/lgpl-2.1.txt. The Original Code is ejMud
 * (Ewerp Java MUD).  The Initial Developer is Curtis Boyden.
 *
 * Software distributed under the GNU Lesser Public License is distributed on an "AS IS" 
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
 * the license for the specific language governing your rights and limitations.
*/

package com.ewerp.mud.commands.admin;

import org.apache.commons.lang.StringUtils;

import com.ewerp.mud.commands.ICommand;
import com.ewerp.mud.commands.parsers.StringCommandParser.IStringParseableCommand;

public class CreateCommandParser implements IStringParseableCommand {

	@Override
	public ICommand parseString(String input) {
		if(StringUtils.isEmpty(input)) {
    		return null;
    	}
    	
        ICommand result = null;
        
        String createCommand = StringUtils.substringBefore(input, " ");
        
        if(!StringUtils.isEmpty(createCommand)) {
        	IStringParseableCommand spc = null;
        	
        	if(createCommand.equalsIgnoreCase("exit")) {
        		spc = new CreateExitCommand();
        	} else if(createCommand.equalsIgnoreCase("room")) {
        		spc = new CreateRoomCommand();
        	}

        	if(spc != null) {
            	result = spc.parseString(StringUtils.substringAfter(input, " "));
            } else {
                System.err.println("Unrecognized create command: " + createCommand);
            }
        }

        return result;
	}

}
